//
//  ZCHotTitleCell.m
//  zctx
//
//  Created by apple on 15/11/25.
//  Copyright © 2015年 sanliang. All rights reserved.
//

#import "ZCHotTitleCell.h"

@implementation ZCHotTitleCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.leftImageView ];
        
        [self.leftImageView  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView.centerY).with.offset(0);
            make.left.equalTo(self.contentView).with.offset(15);
            make.height.mas_equalTo(18);
            make.width.mas_equalTo(@2);
        }];
        
        [self.contentView addSubview:self.leftlable];
        [self.leftlable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView.mas_centerY).with.offset(0);
            make.left.equalTo(self.leftImageView.right).with.offset(5);
            make.bottom.equalTo(self.contentView).with.offset(0);
            make.width.mas_equalTo(@150);
        }];
        
        [self.contentView  addSubview:self.segmented];
        [self.segmented mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView.mas_centerY).with.offset(0);
            make.right.equalTo(self.contentView.right).with.offset(-15);
            make.height.mas_equalTo(25);
            make.width.mas_equalTo(@100);
        }];

    }
    return self;
}
- (void)awakeFromNib {
    // Initialization code
}

-(void)setTitleStr:(NSString *)titleStr{
    _titleStr = titleStr;
    [self.leftlable setText:titleStr];
}

-(UIImageView *)leftImageView{
    if (!_leftImageView) {
        _leftImageView = [UIImageView new];
       [_leftImageView  setImage:[UIImage imageNamed:@"main_left.png"]];
    }
    return _leftImageView;
}

-(UISegmentedControl *)segmented{
    if (!_segmented) {
        _segmented = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"时间",@"热度",nil]];
        _segmented.selectedSegmentIndex=0;
        _segmented.tintColor = [UIColor colorWithHexString:@"a5a5a5"];
        
         NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:12],NSFontAttributeName,[UIColor colorWithHexString:@"a5a5a5"], NSForegroundColorAttributeName,nil];
        [_segmented setTitleTextAttributes:attributes forState:UIControlStateNormal];
        
        NSDictionary *selectAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
        [_segmented setTitleTextAttributes:selectAttributes forState:UIControlStateSelected];
        
         [_segmented addTarget:self action:@selector(doSomethingInSegment:)forControlEvents:UIControlEventValueChanged];
    }
    return _segmented;
}

-(void)doSomethingInSegment:(UISegmentedControl *)Seg
{
    NSLog(@"index = %ld",Seg.selectedSegmentIndex);
    NSInteger Index = Seg.selectedSegmentIndex;
    
    if (_delegate && [_delegate respondsToSelector:@selector(SelectHottitleCell:)]) {
        [_delegate SelectHottitleCell:Index];
    }
}

-(UILabel *)leftlable{
    if (!_leftlable) {
        _leftlable = [UILabel new];
        _leftlable.textColor = [UIColor colorWithHexString:@"#03ab9e"];
        _leftlable.font = [UIFont systemFontOfSize:16];
        [_leftlable setText:@"食品安全资讯"];
    }
    return _leftlable;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
